from Constants import *
import pygame
from pygame.locals import *

class House:
    def __init__(self, houseParts):
        self.houseParts = houseParts
        self.size = (500,500)
        self.canvas = pygame.Surface((self.size[X], self.size[Y])).convert()
        self.colorkey = (255,255,0)
        self.canvas.fill(self.colorkey)
        self.canvas.set_colorkey(self.colorkey)
        self.update()
    
    def setPos(self, pos):
        #offset render pos for entire house canvas
        self.renderPos = (pos[X] -TILE_WIDTH, pos[Y] - TILE_DEPTH * 2)
        
    
    #blit canvas to screen
    def render(self, screen):
        screen.blit(self.canvas, self.renderPos)
        
    #render parts to canvas
    def update(self):
        self.canvas.blit(self.houseParts['Window Tall'], (0, TILE_DEPTH * 2))
        self.canvas.blit(self.houseParts['Roof West'], (0, 0))
        self.canvas.blit(self.houseParts['Door Tall Closed'], (TILE_WIDTH, (TILE_DEPTH * 2) + 20))
        self.canvas.blit(self.houseParts['Roof East'], (TILE_WIDTH, 0))
        
        #leftStack.dropBlock(Block('Brown Block', self.houseBlockImages))
        #leftStack.dropBlock(Block('Window Tall', self.houseBlockImages))
        #leftStack.dropBlock(Block('Roof West',self.houseBlockImages))
        #rightStack.dropBlock(Block('Door Tall Closed', self.houseBlockImages))
        #rightStack.dropBlock(Block('Brown Block', self.houseBlockImages))
        #rightStack.dropBlock(Block('Roof East', self.houseBlockImages))
    
class HousePart:
    def __init__(self, name, imageCache, zHeight=1):
        self.name = name
        self.image = imageCache[name]
        self.zHeight = zHeight
        
    def render(self, screen, pos):
        renderX = pos[X] * TILE_WIDTH
        renderY = (pos[Y] * TILE_Y_SPACING) - (pos[Z] * TILE_DEPTH)
        screen.blit(self.image, renderPos)